using System.Net.Mail;
using System.Text;
using System.Web;
using Mvc.Mailer;
using viBook.Common;
using viBook.Models;

namespace viBook.Mailers
{ 
    public sealed class UserMailer : MailerBase, IUserMailer
    {
        public UserMailer()
        {
            MasterName = "_Layout";
        }

        #region IUserMailer Members

        public MailMessage Activate(User user)
		{
			var mailMessage = new MailMessage{Subject = "Activate your account at ViBook"};
            var link = new StringBuilder(HttpContext.Current.Request.Url.Scheme);
            link.Append("://");
            link.Append(HttpContext.Current.Request.Url.Authority);
            link.Append(Constant.ActivatePath);
            link.Append("?userid=");
            link.Append(user.Id);
            link.Append("&code=");
            link.Append(user.ValidationCode);
			mailMessage.To.Add(user.Email);
            ViewBag.Name = user.DisplayName;
			ViewBag.ActivateLink = link.ToString();
			PopulateBody(mailMessage, "Activate");

            return mailMessage;
        }

		public MailMessage ResetPassword(User user)
		{
			var mailMessage = new MailMessage{Subject = "Reset your account password at ViBook"};
            var link = new StringBuilder(HttpContext.Current.Request.Url.Scheme);
            link.Append("://");
            link.Append(HttpContext.Current.Request.Url.Authority);
            link.Append(Constant.ResetPasswordPath);
            link.Append("?userid=");
            link.Append(user.Id);
            link.Append("&code=");
            link.Append(user.ValidationCode);
            mailMessage.To.Add(user.Email);
            ViewBag.Name = user.DisplayName;
            ViewBag.ResetPasswordLink = link.ToString();

            PopulateBody(mailMessage, "ResetPassword");

            return mailMessage;
        }

        #endregion
    }
}
